<div class="breadcrumb">
    <ul id="breadcrumb">
        <li><a href="<?php echo Configure::read('base_url');?>backstage" title="Home">
		<?php echo $this->Html->image("home.png", array("alt" => "Home",'class'=>'home','border'=>'0'));?>
		</a></li>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/products/ptrack_pending" title="product tracking">Products Tracking - Pending</a></li>
    </ul>
</div>
<?php echo $this->element('admin/admin_leftmenu'); ?>
<div id="left">
    <?php
    echo $this->Session->flash();
    if ($this->Session->check('Message.auth'))
        echo $this->Session->flash('auth');
    ?>
    <div class="div_header"><?php __('Products Tracking - Pending'); ?></div>
    <div class="div_content">
        <div class="paging">
            <?php echo $this->element('admin/product/top_menu'); ?>
		</div>
		<div  style="width:690px; background:  #ccc; margin:5px 0; padding: 5px;color: black;">Search</div>
        <form method="post" id="searchfrm" action="<?php echo Configure::read('base_url')."backstage/products/ptrack_pending"; ?>">
		<table width="70%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td  style="border:0px;text-align: right;">Search By:</td><td   style="border:0px; width: 50px; text-align: left;">
				<input type="text" size="36"  id="serchkey" name="serchkey" class="anyOnerequired" title="Please enter keyword." value="Enter Product Item #, Title or Seller ID" onfocus="if(this.value=='Enter Product Item #, Title or Seller ID'){this.value=''}" onblur="if(this.value==''){this.value='Enter Product Item #, Title or Seller ID'}"/>
		</td><td  style="border:0px;"><select name="data[type]">
			<option value="item">Item #</option>
			<option value="title">Title</option>
			<option value="sellerid">Seller ID</option>
		</select><input type="submit" style="background:#73AE0B;
		color:#fff; font-size:14px;" name="button" id="button" value="Search" />
		</td>
		</tr>
		</table>
		</form>
		<div id='message_success'></div>
        
        <div style="margin-top:5px;">
            <input type="button" class="approve_selected" value="Approve Selected" name="Approve Selected" />&nbsp;
           <a href="javascript:void(0);" controller="products" action="product_disapproved_selected" title="product_disapproved"
                  onclick='showPop(this)'><input type="button" value="Disapprove" /></a>&nbsp;
            <a href="javascript:void(0);" controller="products" action="addnote_selected" title="messagebyitem"
              onclick='showPop(this)'><input type="button" value="Add Note" /></a>&nbsp;            
        </div>
           <table id="category_table" cellspacing="0" class="tablesorter">
            <thead>
                <tr style="background:gray;">
					<th><input type="checkbox" id="select_all" /></th>
					<th>&nbsp;</th>
					<th>Item #</th>
					<th>Title</th>
					<th>Seller</th>
					<th>Status</th>
					<th>Submission Date</th>
					<th>In Progress By</th>
					<th class="actions"><?php __('Actions');?></th>
				</tr>
            </thead>
            <tbody>
                <?php
               $i = 0;
               //pr($products);
               if(!empty ($products)){
                foreach ($products as $product){
                    $class = null;
                    if ($i++ % 2 == 0){
                    $class = ' class="alt"';
                    }
                ?>                                  
                    <tr class="fullrow<?php echo $product['Product']['id']; ?>" id="<?php echo $product['Product']['id']; ?>">
                    <td <?php echo $class;?>  style="vertical-align: middle;"><input type="checkbox" class="products_id" id="<?php echo $product['Product']['id']; ?>" value="<?php echo $product['Product']['id']; ?>" /></td>
                    <td <?php echo $class;?>  style="vertical-align: middle;">
						<?php 
						$image="thumbs/";
						if($product['Product']['products_thumbnailImage']!=""){
						
						echo $html->image( $image.$thumbnail->render($product['Product']['products_thumbnailImage'],
						array('path'=>'thumbs','width'=>140,'height'=>140,'quality'=>80)
						),array('alt'=>$product['Product']['products_title'],'class'=>'shuffle','width'=>80)
						);
						}
						//echo'<img src="'.Configure::read('base_url').'img/uploads/'.$product['Product']['products_thumbnailImage'].'" alt="'.$product['Product']['products_title'].'" width="80" border="0" />';?>
					</td>
                    <td <?php echo $class;?>  style="vertical-align: middle;">
						<?php echo $product['Product']['id']; ?>
                    </td>
                    <td <?php echo $class;?>  style="vertical-align: middle;"><?php echo $product['Product']['products_title']; ?></td>
                    <td <?php echo $class;?>  style="vertical-align: middle;"><?php echo $product['User']['username']; ?></td>
                    <td <?php echo $class;?> style="vertical-align: middle;"> 
                    <?php
                    $inprogress = $this->requestAction('/messages/chkprogress/'.$product['Product']['id'].'/'.$product['Product']['user_id']);
                    //pr($inprogress);
                    if(!empty ($inprogress)){
                        echo'<img src="'.Configure::read('base_url').'img/email.jpeg"  border="0" /><br/>';
                    }
                    ?>
                    <?php echo $product['Product']['products_status']; ?>
                    </td>
                    <td <?php echo $class;?> style="vertical-align: middle;">
                     <?php echo date('d/m/Y',  strtotime($product['Product']['products_createDate'])); ?>
                    </td>
                    <td  <?php echo $class;?> style="vertical-align: middle;">
                    <?php
                    if(!empty ($inprogress)){
                        echo $inprogress[0]['Sender']['username'];
                    }  else {
                        echo 'none';
                    } ?>
                    </td>
        <td align="center"  <?php echo $class;?> style="vertical-align: middle;">
             <?php if($session->read('grouptype')!='S-Admins'){?>
            <input type="button" value="Approve" class="approve_product" id="<?php echo $product['Product']['id']; ?>"/>&nbsp;&nbsp;
            <a href="javascript:void(0);" controller="products" action="product_disapproved" title="product_disapproved"
               ElmID="<?php echo $product['Product']['id']; ?>"
                onclick='showPop(this)'>
            <input type="button" value="Disapprove" id="<?php echo $product['Product']['id']; ?>"/>
            </a>
            <br/><br/>
            <?php
             }
            ?>
            <?php
            if(!empty ($inprogress) OR ($session->read('grouptype')!='S-Admins')){
            ?>
            <a href="javascript:void(0);" controller="messages" action="messagebyitem" title="messagebyitem"
               ElmID="<?php echo $product['Product']['id']; ?>" ElmID2="1" onclick='showPop(this)'>
            <input type="button" value="Messages" /></a>
            <?php
            }
            ?>
             <?php if($session->read('grouptype')!='S-Admins'){?>
            &nbsp;&nbsp;
            <a href="javascript:void(0);" controller="products" action="addnote_pending" title="messagebyitem"
               ElmID="<?php echo $product['Product']['id']; ?>" ElmID2="<?php echo $product['Product']['user_id']; ?>" onclick='showPop(this)'>
            <input type="button" value="Add Note" /></a>
            <?php
             }
            ?>
        </td>

                </tr>               
        <?php
        $comments = $this->requestAction('/products/getnote/' . $product['Product']['id'] . '/' . $product['Product']['user_id'] . '/' . '1');
        //pr($comments);
        if (!empty($comments)) {
        ?>
       <tr    class="fullrow<?php echo $product['Product']['id']; ?>" >
            <td colspan="9" id="disnote<?php echo $product['Product']['id']; ?>" style="background: none repeat scroll 0pt 0pt BlanchedAlmond;">
    <?php
        
        foreach($comments as $comment) {
        echo '<b>'.$comment['User']['username'].' [ '.date('d-m-Y g:i A',  strtotime($comment['Note']['created'])).' ] : </b> '.$comment['Note']['note'];echo"<br/>";
        //$j++;

        }
?>
</td></tr>
    <?php

        }
    }

        }else{
        ?>
        <tr>
        <td colspan="9">
        No Pending Product Found.
        </td>
        </tr>
        <?php
        }
        ?>
                   <tbody>
                </table>
         <div>
            <input type="button" class="approve_selected" value="Approve Selected" name="Approve Selected" />&nbsp;
           <a href="javascript:void(0);" controller="products" action="product_disapproved_selected" title="product_disapproved"
                  onclick='showPop(this)'>
            <input type="button" value="Disapprove" />
            </a>&nbsp;
            <a href="javascript:void(0);" controller="products" action="addnote_selected" title="messagebyitem"
              onclick='showPop(this)'>
            <input type="button" value="Add Note" /></a>&nbsp;

        </div>
        <div class="paging">
		<?php
                if($type!=null){
                $paginator->options(array('url' => "$serchkey/$type"));
                }
                echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled')); ?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
	</div>
            </div>
            <div class="div_bottom"></div>
        </div>

        <!-- edit sidebar items here -->

        </div>

<?php echo $html->script(array("jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js","jquery.validate.js")); ?>
<script type="text/javascript"> 
      jQuery(document).ready(function(){
        jQuery("#category_table").tablesorter({headers: {0:{sorter: false},1:{sorter: false},8:{sorter: false}, 5:{sorter: false}}});

 jQuery.validator.addMethod("anyOnerequired", function (value, element) {
             var serchkey=jQuery("#serchkey").val();
            
          if(serchkey=='' || serchkey=='Enter Product Item #, Title or Seller ID'){return false;}else{return true;}


    }, "This field is required.");

 var v = jQuery("#searchfrm").validate({

                       });

jQuery("#select_all").click(function(){
				var checked_status = this.checked;
				jQuery("input[class=products_id]").each(function()
				{
                                 this.checked = checked_status;
    				});
});
        /////////////approve////////////////////
    jQuery(".approve_product").click(function()
    {
        var pid=jQuery(this).attr('id');
        var con=confirm('Do you really want to approve the selected product?');
        if(con){
            jQuery.ajax({
                url : baseurl+"products/product_approved/"+pid,
            success : function (html) {
                jQuery('.fullrow'+pid).remove();
            }
        });
      
    }
});

  //approved all selected
  jQuery(".approve_selected").click(function()
       {
           var check=false;
           jQuery("input[class=products_id]").each(function()
           {
               //var mid= jQuery(this).val();
               var checked_status=this.checked;
               if(checked_status==true){
                   check=true;
               }
           });

           if(check){
               var r=confirm("Do you really want to approve the selected product(s)?");
               if (r){
                   jQuery("input[class=products_id]").each(function()
                   {
                       var pid=jQuery(this).attr('id');
                       var checked_status=this.checked;
                       if(checked_status==true){
                           /////////////////////////////
                           jQuery.ajax({
                               url : baseurl+"products/product_approved/"+pid,
                               success : function (html) {
                                   jQuery('.fullrow'+pid).remove();
                               }
                           });
                           /////////////////////////////////
                       }
                   });
               }
               
           }else{
               alert('Please select at least One Product!');
               return false;
           }

       });
});
</script>